<?php


namespace App\Http\Controllers;
use App\Common\Business\Users;
use  App\Http\Requests\RegisterPost;
use Illuminate\Http\Request;


class RegisterController extends Controller
{
    public function index(Request $request)
    {
        if ($request->has('id')) {
            $users = (new Users)->listsTree($request->id);
        } else {
            $users = (new Users)->listsTree();
        }

        // 这是通过遍历获得的无限极分类,用于接口方面
//        $users2 = (new Users)->listsTree2();
//        dd($users2);
        return view('users/register', compact('users'));
    }

    public function register(RegisterPost $request)
    {
        $data = $request->validated();
        // 模拟数据
        $data['email']  = 123;
        $data['password']  = 123;
        $data['email_verified_at']  = '2021-05-04 21:26:25';
        $data['mrp']  = 0;

        $res = (new Users)->register($data);
        if (!$res) {
            return \Redirect::back()->withErrors('注册失败');
        }
        return redirect('/')->withErrors('注册成功');
    }

    public function info()
    {
        return (new Users)->info();
    }
}
